package com.huawei.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by minshiwu on 2017/2/8.
 */
@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.getParameter("username");
        req.getParameter("password");
        req.getSession().setAttribute("user", req.getParameter("username"));
        //将user放在Attribute中

        req.getRequestDispatcher("success.html").forward(req, resp);
        //校验用户名密码正确，跳转到welcome.jsp
    }
}
